home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Demos
/
A.D. Software
/
OOFILE
/
PhoneControl OOFILE sample
/
Source
/
CPhoneControlDoc.cp
< prev
next >
Wrap
Text File
|
1996-06-16
|
8KB
|
319 lines
// CPhoneControlDoc.cp -- Document methods
// Created 01/01/95 12:01 PM by AppMaker
#include "CPhoneControlDoc.h"
#include "CPhoneControlApp.h"
#include "CMainWindow.h"
#include "CImporting.h"
#include "CCompletedImport.h"
#include <LFile.h>
#include <LPlaceHolder.h>
#include <LPrintout.h>
#include <LWindow.h>
#include <UWindows.h>
#include <String_Utils.h>
#include <UDesktop.h>
#include <PP_Messages.h>
#include "PhoneControl_OOFILE.h"
//#include "oofctrex.hpp" // not normally - just to expose the backend file mode, for now
#include "CPeriodicImport.h"
#include "stSetCursor.h"
#include <UModalDialogs.h>
const ResIDT prto_PrintView = 201;
const ResIDT STRx_Untitled = 128;
// ---------------------------------------------------------------------------
// • CPhoneControlDoc
// ---------------------------------------------------------------------------
CPhoneControlDoc::CPhoneControlDoc(
LCommander *inSuper)
: LSingleDoc(inSuper)
, mData(0)
, mPhoneControl(0),
mImportTimer(0)
{
}
// ---------------------------------------------------------------------------
// • ~CPhoneControlDoc
// ---------------------------------------------------------------------------
// Destructor
//
CPhoneControlDoc::~CPhoneControlDoc()
{
delete mData;
delete mPhoneControl;
delete mImportTimer;
}
//----------
void
CPhoneControlDoc::newFile()
{
FSSpec fileSpec;
if (AskSaveAs(fileSpec, true)) {
MakeDatabaseObjects();
mData->newConnection(OOF_MacString(fileSpec.name));
CompleteOpenFile(&fileSpec);
}
}
//----------
void
CPhoneControlDoc::openFile(
FSSpec *inFileSpec)
{
MakeDatabaseObjects();
#ifdef BLIND_OPEN
mData->openConnection(CPhoneControlApp::sDatabaseLocationPath);
FSSpec dummyMacFSSpec;
const char* windowName = "Directory Services ARIES - [Personnel Directory]";
long nameLen = strlen(windowName);
memcpy((char*) &(dummyMacFSSpec.name[1]), windowName, nameLen);
dummyMacFSSpec.name[0] = nameLen;
// fake filename used as a window title
CompleteOpenFile(&dummyMacFSSpec);
// setup importing
if (CPhoneControlApp::sImporting) {
unsigned long startImportAt;
Date2Secs(&CPhoneControlApp::sStartImport, &startImportAt);
mImportTimer = new CPeriodicImport(this, startImportAt, CPhoneControlApp::sImportInterval);
assert(mImportTimer);
}
#else
mData->openConnection(OOF_MacString(inFileSpec->name));
CompleteOpenFile(inFileSpec);
#endif
}
// ---------------------------------------------------------------------------
// • DoPrint
// ---------------------------------------------------------------------------
// Print the contents of the Document
void
CPhoneControlDoc::DoPrint()
{
LPrintout *thePrintout = LPrintout::CreatePrintout(prto_PrintView);
LPlaceHolder *textPlace = (LPlaceHolder *)
thePrintout->FindPaneByID('TBox');
//! textPlace->InstallOccupant(mTextView, atNone);
thePrintout->DoPrintJob();
delete thePrintout;
}
void CPhoneControlDoc::DoImport()
{
// copied from AppMaker-generated CPhoneControlApp::ChooseDocument()
SFTypeList typeList;
short numTypes;
StandardFileReply macFileReply;
typeList[0] = 'TEXT'; // only type we import
numTypes = 1;
UDesktop::Deactivate();
::StandardGetFile(nil, numTypes, typeList, &macFileReply);
UDesktop::Activate();
if (macFileReply.sfGood) {
OSErr iErr = noErr; // SetVol(0, macFileReply.sfFile.vRefNum); // in case choose file in another dir
if (iErr==noErr) {
char fname[64];
long nameLen = macFileReply.sfFile.name[0];
memcpy(fname, &(macFileReply.sfFile.name[1]), nameLen);
fname[nameLen] = '\0';
importFromFile(fname); // DO IT!
}
}
}
void CPhoneControlDoc::importFromFile(const char* inFname)
{
if (!dbConnect::fileExists(inFname)) {
dbConnect::raise(ostrstream() << "Sorry, couldn't find import file: " << inFname);
return;
}
ifstream inFile(inFname);
if (inFile.good()) {
{
// Display message while importing
StDialogHandler importDialogHandler(rPPob_Importing, this); // will vanish at end of procedure
// force display of the panes in the dialog that aren't covered by a RidL
importDialogHandler.DoDialog(); // finish creating the bits in the dialog
{
LWindow* impMsg = importDialogHandler.GetDialog();
assert(impMsg);
impMsg->Refresh();
}
importDialogHandler.DoDialog(); // respond to the refresh
stSetCursor showWatch; // AFTER the DoDialog, otherwise that changes back to arrow
// mData->enterWriteLocking();
mPhoneControl->deleteAll();
inFile >> *mPhoneControl;
// mData->exitLocking();
} // end of frame for import process
// Display message and wait for the user to press OK
StDialogHandler completedImportDialogHandler(rPPob_CompletedImport, this); // will vanish at end of procedure
// force display of the panes in the dialog that aren't covered by a RidL
completedImportDialogHandler.DoDialog(); // finish creating the bits in the dialog
{
CCompletedImport* impMsg = (CCompletedImport*) completedImportDialogHandler.GetDialog();
assert(impMsg);
impMsg->SetImported(mPhoneControl->countAll());
impMsg->Refresh();
}
for (;;) {
MessageT msg = completedImportDialogHandler.DoDialog(); // respond to the refresh
if (msg == msg_OK)
break;
}
// redisplay all the new records
mPhoneControl->selectAll();
recordHasBeenChanged(); // tell the browser
}
}
void
CPhoneControlDoc::DoSaveAsText()
{
FSSpec fileSpec;
if (AskSaveAs(fileSpec, true)) {
char fname[64];
long nameLen = fileSpec.name[0];
memcpy(fname, &(fileSpec.name[1]), nameLen);
fname[nameLen] = '\0';
ofstream outFile(fname);
stSetCursor showWatch; // cursor will change back to pointer on exit from method
outFile << *mPhoneControl;
outFile.close();
}
}
//----------
Boolean
CPhoneControlDoc::ObeyCommand(
CommandT inCommand,
void *ioParam)
{
Boolean cmdHandled = true;
switch (inCommand) {
// +++ Add cases here for the commands you handle
// Remember to add same cases to FindCommandStatus below
// to enable/disable the menu items for the commands
case 'SvTx' :
DoSaveAsText();
break;
case 'Impt' :
DoImport();
break;
default:
cmdHandled = LSingleDoc::ObeyCommand(inCommand, ioParam);
break;
}
return cmdHandled;
}
//----------
void
CPhoneControlDoc::FindCommandStatus(
CommandT inCommand,
Boolean &outEnabled,
Boolean &outUsesMark,
Char16 &outMark,
Str255 outName)
{
outUsesMark = false;
switch (inCommand) {
// +++ Add cases here for the commands you handle
case 'Impt' :
outEnabled = true;
break;
case 'SvTx':
outEnabled = true;
break;
default:
LSingleDoc::FindCommandStatus(inCommand, outEnabled,
outUsesMark, outMark, outName);
break;
}
}
//----------
void
CPhoneControlDoc::MakeDatabaseObjects()
{
// MUST TAKE PLACE BEFORE newConnection or openConnection
// you can't define dbTables after opening the connection
// Note if these were defined as part of CFIleAndFindDoc, instead of being
// 'newed' heap-based objects, this method would not be necessary
mData = new dbConnect_ctree;
// create all database tables
mPhoneControl = new CdbPhoneControl;
// change types of files created by c-tree (given modification to ctclib.c)
ctMacCreator = kSignature;
ctMacType = kFileType;
}
//----------
void
CPhoneControlDoc::CompleteOpenFile(
FSSpec *inFileSpec)
{
// can now make the factories for our database editing windows and dialogs
// which require us to have constructed the database objects
AdoptBrowseWindowFactory(new CMainWindowFactory(this, mPhoneControl));
mWindow = MakeBrowser();
if (mWindow != nil) {
mWindow->SetDescriptor (inFileSpec->name);
}
mIsSpecified = true;
}